// pages/notice/notice.js
Page({
    data: {
        cardCur: 0,
        msg: '',
        swiperList: [{
          //读书小组
          id: 16, //该轮播图对应的通知或项目的id
          class: '1',  //class=1表示是通知公告，0是项目展示
          type: 'image', //这个参数是固定不变的
          url: 'https://pic.imgdb.cn/item/62ca79eaf54cd3f9370715df.png'
        }, {
          id: 15,
          class: '1',
          type: 'image',//疫情项目
          url: 'https://pic.imgdb.cn/item/62ca79eaf54cd3f9370715e8.png',
        }, {
          id: 4,
          class: '0',//class=0表示是展示项目
          type: 'image',//音乐治疗
          url: 'https://pic.imgdb.cn/item/62ca79eaf54cd3f9370715f4.png'
        }],
        content:'',
        noticeList: [],
    },
    cardSwiper(e) {
      this.setData({
        cardCur: e.detail.current
      })
    },
    
    // 输入事件
    input(e){
      this.setData({
        content: e.detail.value
      })
    },
    // 跳转到搜索结果界面,x携带参数为搜索内容content、搜索类型type
    gotoSearch(e){
        wx.navigateTo({
          url: '/pages/notice/search_notice/search_notice?content='+this.data.content+'&type=通知公告',
        })
        
    },

    // 跳转到“创新创业训练计划”页面
    gotoInnovation(e) {
      wx.navigateTo({
        url: '/pages/notice/noticeOfInnovation/noticeOfInnovation',
      })  
    },
    // 跳转到“学科竞赛”页面
    gotoContest(e) {
      wx.navigateTo({
        url: '/pages/notice/noticeOfContest/noticeOfContest',
      })
    },
     //跳转到搜索(首页)页面
    search(e) {
      wx.navigateTo({
        url: '/pages/notice/search_notice/search_notice',
      })
    },

    //轮播图跳转到详情
    displayInfo(e){
      console.log(e);
      if(e.target.dataset.class==1){
        wx.navigateTo({
          url: '/pages/notice/detailOfNotice/detailOfNotice?id='+e.target.dataset.id,
        })
      }else{
        wx.navigateTo({
          url: '/pages/display/display-info/display-info?id=' + e.target.dataset.id,
        })
      }
    },
    // 用于设置传给后端的参数
    Parameters: {
      pageParam: {
        orderBy: "publish_date desc",
        pageNum: 1,
        pageSize: 5
      },
      type: "ALL"
    },
    // 用于设置总页数
    totalPages: 1,
    //获取轮播图
    getPhoto(e){
      wx.request({
        url: 'https://www.hschuangsai.com/carousel/list',
        data: {number:3},
        method: 'GET',
        success: (result) => {
          console.log("轮播图",result.data.data[0])
          this.setData({
            'swiperList[0].url' : result.data.data[0].url,
            'swiperList[1].url' : result.data.data[1].url,
            'swiperList[2].url' : result.data.data[2].url,
            'swiperList[0].id' : result.data.data[0].projectId,
            'swiperList[1].id' : result.data.data[1].projectId,
            'swiperList[2].id' : result.data.data[2].projectId,
            'swiperList[0].class': result.data.data[0].projectType,
            'swiperList[1].class': result.data.data[1].projectType,
            'swiperList[2].class': result.data.data[2].projectType,
          })
        },
      })
    },
   /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.setData({
        'selectItems[0].checked': true,
    });
      this.getPhoto();
      wx.request({
        url: 'https://www.hschuangsai.com/notification/list',
        data: this.Parameters,
        method: "POST",
        success: (result) => {
          this.totalPages=result.data.data.pages;
          console.log("noticeList",result.data.data.list)
          this.setData({
            noticeList: result.data.data.list
          })
          }
      })
    },

 

   /**
     * 页面上拉触底事件的处理函数(上拉触底，加载更多数据)
     */
    onReachBottom: function () {
      this.Parameters.pageParam.pageNum+=1;
      if(this.Parameters.pageParam.pageNum>this.totalPages){
        //console.log('加载失败')
      }else{
        wx.request({
          url: 'https://www.hschuangsai.com/notification/list',
          data: this.Parameters,
          method: "POST",
          success: (result) => {
            console.log("noticeList",result.data.data.list)

            this.setData({
              noticeList: [...this.data.noticeList,...result.data.data.list]
            })
          },
        })
      }
    },
  
})